﻿IEnumerable<Student> query = from s in students
                             where s.Major == "computer science"
                             select s;
var query = students.Where(s => s.Major == "computer science");
//多个where语句
var query = from s in students
            where s.Major == "computer science" && s.ID != "011"
            select s;
var query from s in students
    where s.Major == "computer science"
    where s.ID !="011"
    select s;

var query = students
    .Where(s => s.Major == "computer science")
    .Where(s => s.ID != "011");
//二次过滤
var query 2 = from s in query
    where s.ID != "011"
    select s;//select s.Name,select new{s.Name,s.Id}

//匿名数据类型示例
var student = new { Name = "Mary Jones", Age = 15, Major = "History" };
Console.WriteLine($"{student.Name},Age:{student.Age},Major{student.Major}");

//OrderBy 子句
var query1 = from s in students where s.Major == "computer science"
             orderby s.ID 
             select s;
             

var query2 = from s in students where s.Major == "computer science"
             orderby s.ID descending//ID降序
             select s;

var query1 = student.Where(s => s.Major == "computer science")
    .OrderBy(student => student.ID)//OrderByDescending
//多字段排序
var query1 = from s in students where s.Major == "computer science"
    orderby s.Name, s.ID descending
    select s;
var query2 = student.Where(s => s.Major == "computer science").OrderBy(s => s.Name)
    .ThenByDescending(s => s.ID);

//将IEnumerable类型的数据转换为List，Array，Dictionary
var query = students.Where(s => s.Major == "computer science");
student[] array = query.ToArray();
List<Student> list = query.ToList();
Dictionary<string, Student> dic = query.ToDictionary(s => s.ID);
//计数，求和，求平均，取第一个数据
int count = query.Count();
int sum = query.Sum(s => s.Age);
double average = query.Average(s=>s.Age);
student student = query.First();

